package com.gmall.rabbitmq.consumer.service;

import com.gmall.rabbitmq.config.RabbitMQConfig_WorkQueue;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class RabbitMQServive_WorkQueue {

    @Autowired
    RedisTemplate redisTemplate;

    @RabbitListener(queues = RabbitMQConfig_WorkQueue.Queue_WorkQueue,concurrency = "1")
    public void receive_WorkQueueMessage(Channel channal, Message message,String msg){
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        String messageId = message.getMessageProperties().getMessageId();

//        System.out.println("------ WorkQueue Start-------");
//        System.out.println("MessageID:" + messageId);
       System.out.println("ThreadID=" + Thread.currentThread().getId()
               + " MessageBody:" + new String(message.getBody()));
//        System.out.println("msg:" + msg);
//        System.out.println("------ WorkQueue End-------");

        try {
            channal.basicAck(deliveryTag,false);
        } catch (IOException e) {

            throw new RuntimeException(e);
        }
    }

}
